using System;
using System.Collections.Generic;
using System.Text;
using Customs.Components.KDT.Khac.Info;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Data;
namespace Customs.Components.KDT.Khac
{
    public class ChungTu : ChungTuInfo
    {
        public void Load(ChungTuInfo entityInfo)
        {
            this._FileUpload = entityInfo.FileUpload;
            this._Ma_HQTN = entityInfo.Ma_HQTN;
            this._Nam_TN = entityInfo.Nam_TN;
            this._So_TNDKDT = entityInfo.So_TNDKDT;
            this._SoBanChinh = entityInfo.SoBanChinh;
            this._SoBanSao = entityInfo.SoBanSao;
            this._STTHang = entityInfo.STTHang;
            this._TenChungTu = entityInfo.TenChungTu;
        }

        //---------------------------------------------------------------------------------------------

        public int Insert(SqlTransaction transaction)
        {
            StringBuilder query = new StringBuilder();
            query.Append("INSERT INTO DCHUNGTUKEM ( ");
            query.Append("So_TNDKDT, ");
            query.Append("MA_HQTN, ");
            query.Append("Nam_TN, ");
            query.Append("STTHang, ");
            query.Append("TenChungTu, ");
            query.Append("SoBanChinh, ");
            query.Append("SoBanSao ");           
            query.Append(") ");
            query.Append("VALUES (");
            query.Append("@So_TNDKDT, ");
            query.Append("@MA_HQTN, ");
            query.Append("@Nam_TN, ");
            query.Append("@STTHang, ");
            query.Append("@TenChungTu, ");
            query.Append("@SoBanChinh, ");
            query.Append("@SoBanSao ");           
            query.Append(") ");

            SqlParameter[] parameters = new SqlParameter[7];

            parameters[0] = new SqlParameter("@So_TNDKDT", SqlDbType.BigInt);
            parameters[0].Direction = ParameterDirection.Input;
            parameters[0].Value = this.So_TNDKDT;

            parameters[1] = new SqlParameter("@MA_HQTN", SqlDbType.Char);
            parameters[1].Size = 6;
            parameters[1].Direction = ParameterDirection.Input;
            parameters[1].Value = this.Ma_HQTN;

            parameters[2] = new SqlParameter("@Nam_TN", SqlDbType.SmallInt);
            parameters[2].Direction = ParameterDirection.Input;
            parameters[2].Value = this.Nam_TN;

            parameters[3] = new SqlParameter("@STTHang", SqlDbType.Int);
            parameters[3].Direction = ParameterDirection.Input;
            parameters[3].Value = this.STTHang;

            parameters[4] = new SqlParameter("@TenChungTu", SqlDbType.NVarChar);
            parameters[4].Size = 50;
            parameters[4].Direction = ParameterDirection.Input;
            parameters[4].Value = this.TenChungTu;

            parameters[5] = new SqlParameter("@SoBanChinh", SqlDbType.SmallInt);
            parameters[5].Direction = ParameterDirection.Input;
            parameters[5].Value = this.SoBanChinh;

            parameters[6] = new SqlParameter("@SoBanSao", SqlDbType.SmallInt);
            parameters[6].Direction = ParameterDirection.Input;
            parameters[6].Value = this.SoBanSao;
          

            return SqlHelper.ExecuteNonQuery(transaction, CommandType.Text, query.ToString(), parameters);			
        }

        public static int DeleteByForeignKey(long soTiepNhan, string maHaiQuan, int namTiepNhan, SqlTransaction transaction)
        {
            string sql = "delete DCHUNGTUKEM where So_TNDKDT=@So_TNDKDT and Ma_HQTN=@Ma_HQTN and Nam_TN=@Nam_TN";
            SqlParameter[] parameters = new SqlParameter[3];

            parameters[0] = new SqlParameter("@So_TNDKDT", SqlDbType.BigInt);
            parameters[0].Direction = ParameterDirection.Input;
            parameters[0].Value = soTiepNhan;

            parameters[1] = new SqlParameter("@MA_HQTN", SqlDbType.Char);
            parameters[1].Size = 6;
            parameters[1].Direction = ParameterDirection.Input;
            parameters[1].Value = maHaiQuan;

            parameters[2] = new SqlParameter("@Nam_TN", SqlDbType.SmallInt);
            parameters[2].Direction = ParameterDirection.Input;
            parameters[2].Value = namTiepNhan;
            return SqlHelper.ExecuteNonQuery(transaction, CommandType.Text, sql, parameters);			
        }
    }
}
